package com.example.controller;

import com.example.domain.message.MessageConstant;
import com.example.domain.pojo.CheckGroup;
import com.example.domain.pojo.Setmeal;
import com.example.domain.result.Result;
import com.example.service.SetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/setmeal")
public class SetMealController {
    @Autowired
    private SetMealService setMealService;

    //查询所有的套餐信息
    @RequestMapping("/getSetmeal")
    public Result findAll(){
        try {
            List<Setmeal> setmealList= setMealService.findAll();
            return  new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmealList);
        } catch (Exception e) {
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }


    //根据套餐id查找套餐的全部信息
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Setmeal setmeal=  setMealService.findById(id);
            /*StringBuilder sb=new StringBuilder();
            List<CheckGroup> checkGroups = setmeal.getCheckGroups();
            for (CheckGroup checkGroup : checkGroups) {
                sb.append(checkGroup.getName());
            }

            setmeal.setDetail(sb.toString());*/

            return  new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmeal);
        } catch (Exception e) {
            return new Result(false,MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }
}
